package com.itheima.management.controller;


import com.itheima.management.service.ManageCommentService;
import com.itheima.management.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/manage/messages")
public class ManageCommentController {


    @Autowired
    private ManageCommentService manageCommentService;


    /**
     *
     *                          评论列表翻页
     *
     * @param publishId
     * @param page
     * @param pageSize
     * @param sortProp
     * @param sortOrder
     * @return
     */
    @GetMapping("comments")
    public ResponseEntity<PageResult> loginRecord(@RequestParam("messageID") String publishId,
                                                  @RequestParam(value = "page", defaultValue = "1") Integer page,
                                                  @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize,
                                                  @RequestParam("sortProp") String sortProp,
                                                  @RequestParam("sortOrder") String sortOrder) {

        try {
            if (page <= 0) {
                page = 1;
            }
            PageResult pageResult = this.manageCommentService.queryCommentList(publishId, page, pageSize, sortProp, sortOrder);

            if (pageResult != null) {

                return ResponseEntity.ok(pageResult);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}